package Lee_code;

import java.util.HashSet;

class Trie {
    HashSet<String> hashSet = new HashSet<>();

    public Trie() {
    }

    public void insert(String word) {
        hashSet.add(word);
    }

    public boolean search(String word) {
        for (String string : hashSet) {
            if (word.equals(string)) {
                return true;
            }
        }
        return false;
    }

    public boolean startsWith(String prefix) {
        int len = prefix.length();
        for (String string : hashSet) {
            if (string.length() >= len) {
                if (string.substring(0, len).equals(prefix)){
                    return true;
                }
            }
        }
        return false;
    }
}